Helpful Information
 
 
Category: C++
C++->MySQL connection problem

Hello...

I'm trying to use borland C++ builder 6 to connect to a MySQL database. I allready downloaded the library files provided by mysql.com and I added them to my project via Project->AddToProject->libmysql.lib. I run into problems when I try to compile the following, very simple program:

#include <windows.h>
#include <mysql.h>

void main() {
MYSQL *conn;
conn = mysql_init(NULL);
}


The compiler returns a linker error on "conn = mysql_init(NULL);"

Does anyone know how to solve this?

>>Project->AddToProject->libmysql.lib

I don't use Borland but did you link to the libraries or just add them? In MSVC you would have to add them in the linker not to the project.

>>void main()

If your complier does not tell you this is an error you need a new complier.

As the app WILL return an int to the OS, better to define one.

the standard says

"The function called at program startup is named main. The implementation declares no prototype for this function. It shall be defined with a return type of int and with no parameters:

code:int main(void) { /* ... */ }


or with two parameters (referred to here as argc and argv, though any names may be used, as they are local to the function in which they are declared):

code:
int main(int argc, char *argv[]) { /* ... */ }


or equivalent; or in some other implementation-defined manner."

"Have you included the libraries for the headers?"

I dont think so, I only included libmysql.lib. Are there any other files that I should include?

Adding the library to the project is not sufficient to cause it to link. You need to go into the project options, on the linker tab, and explicitly request that this module be linked. Any time you get an error message about an undefined reference, with any compiler, it is always a linking problem.










privacy (GDPR)